package com.oocl.euc.core.builder;

import com.oocl.euc.core.maintenance.model.RoleAuth;
import com.oocl.euc.core.maintenance.model.SupportGroup;
import com.oocl.euc.core.maintenance.model.Users;
import com.oocl.euc.core.maintenance.repository.RoleAuthRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RoleAuthBuilder {

    private RoleAuth roleAuth;
    @Autowired private RoleAuthRepository roleAuthRepository;

    public RoleAuthBuilder defaultBuilder() {
        this.roleAuth = new RoleAuth();
        return this;
    }

    public RoleAuthBuilder withSupportGroup(SupportGroup supportGroup){
        this.roleAuth.setSupportGroup(supportGroup);
        return this;
    }

    public RoleAuthBuilder withUsers(Users users){
        this.roleAuth.setUsers(users);
        return this;
    }

    public RoleAuth create() {
        return this.roleAuth;
    }

    public RoleAuth saveToDB() {
        roleAuthRepository.save(this.roleAuth);
        return this.roleAuth;
    }
}
